[osmosis-dev] Android?

\url{http://lists.openstreetmap.org/pipermail/osmosis-dev/2012-November/001410.html}

Adrià Ribatallada Torelló achtungwolf at gmail.com 
Tue Nov 6 16:41:55 GMT 2012


\begin{verbatim}
Hi there!

I was trying to use the osmosis tool in an android device, and
after including all the required libraries to an android project and make
it compile and install in the device I'v encountered some "runtime"
obstacles that made me consider that the best approach might be to adapt
the osmosis source code, adapting it to use the android libraries.

(the most severe "obstacle" is a "No validating SAXParser implementation
available" while trying to read the file plugin.xml. Is the same error
explained here with more detail by this other guy:
http://stackoverflow.com/questions/10222230/trying-to-use-osmosis-in-
android-environment-duplicate-file-error-with-jar-file/13251374#13251374
).

So right now I'm trying to "port" osmosis or at least part of it to use it
on an Android device.

But before I start what I consider a huge amount of work, I must ask:

Has somebody tried to do that or something similar in the past? ( I
couldn't found anyone, but maybe I'm not searching in the right places)

Is there (a priori) any reason why this endeavor should fail miserably?

Thanks in advance for any help you might provide.

Sincerely,

Adrià Ribatallada i Torelló.

\end{verbatim}


Raphael Volz rv at nogago.com 
Tue Nov 6 16:50:23 GMT 2012


\begin{verbatim}

Hi Adria,
I don't know why you would want to have osmosis on an Android device, but
nevertheless, if you want to achieve this, you need to implement those
libraries used from Java SDK that are not present in the Android SDK. For
many, you will find a open source implementations in openjdk
http://hg.openjdk.java.net/.
You will have to rename the packages (e.g. appending a common prefix to
avoid conflicts, and do so throughout the osmosis code base).

Good luck +

Raphael



Adrià Ribatallada Torelló achtungwolf at gmail.com 
Tue Nov 6 17:19:06 GMT 2012



> Hi Adria,
> I don't know why you would want to have osmosis on an Android device,
>

I wanted to do so because I'm creating an android app that uses the
mapsforge library, and I was trying to convert downloaded osm data to the
"mapsforge format" to use it later in offline mode, and the way mapsforge
converts from osm to its internal map format is by using an osmosis plugin,
so I thought it may be possible to perform that task in the device itself.

but nevertheless, if you want to achieve this, you need to implement those
> libraries used from Java SDK that are not present in the Android SDK. For
> many, you will find a open source implementations in openjdk
> http://hg.openjdk.java.net/.
> You will have to rename the packages (e.g. appending a common prefix to
> avoid conflicts, and do so throughout the osmosis code base).
>

Ok, many thanks. I'll start to fiddle with it right away.

>
> Good luck +
>
>
Raphael
>
> Thanks again :D

\end{verbatim}


Brett Henderson brett at bretth.com 
Wed Nov 7 10:29:35 GMT 2012


\begin{verbatim}

Hi Adrià,

On 7 November 2012 03:41, Adrià Ribatallada Torelló
<achtungwolf at gmail.com>wrote:

> Hi there!
>
> I was trying to use the osmosis tool in an android device, and
> after including all the required libraries to an android project and make
> it compile and install in the device I'v encountered some "runtime"
> obstacles that made me consider that the best approach might be to adapt
> the osmosis source code, adapting it to use the android libraries.
>
> (the most severe "obstacle" is a "No validating SAXParser implementation
> available" while trying to read the file plugin.xml. Is the same error
> explained here with more detail by this other guy:
> http://stackoverflow.com/questions/10222230/trying-to-use-osmosis-
in-android-environment-duplicate-file-error-with-jar-file/13251374#13251374
> ).
>

I'm not sure if this helps, but the plugin.xml loading code is used by JPF
(Java Plugin Framework) support.  JPF provides one way of packaging Osmosis
plugins, but is rarely used.  The majority of plugins use a simpler
mechanism involving a properties file called osmosis-plugin.conf bundled in
each plugin jar file.  If you don't need JPF you could remove the JPF code
from Osmosis completely and eliminate the error you're receiving.

Brett

\end{verbatim}


Adrià Ribatallada Torelló achtungwolf at gmail.com 
Thu Nov 8 20:37:36 GMT 2012


\begin{verbatim}

Thank you Brett, I'v followed your advice and tried to remove the JPF from
a local clone of the osmosis source, and adapted the plugin I need to use
the osmosis-plugins.conf.

And all compiles good and fine, and if I execute the command I need using
the bin/osmosis script in my machine all goes fine.

But in the Android device I need to do it from the code (or so I think),
calling Osmosis.run(args) or Osmosis.main() I presume, and there is where
it fails now...

That's the code I'm trying to run:

        File pbfFile = new
File(Environment.getExternalStorageDirectory()+"/download/"+"in.osm.pbf");
File outFile = new
File(Environment.getExternalStorageDirectory()+"/download/"+"out.map");

Osmosis.main(new String[] {
"--read-pbf file="+pbfFile,
"--mapfile-writer file="+outFile
});

That's my pretty error:

[..]

I assume that is thrown because the envirenoment it's not well configured,
but I don't know how to "do the same" that does the script from my program
code :P

I'v tried to run the classworlds.Launcher, but I didn't suceed there...

Can some of you help me understand what needs to be done "programatically"
to setup the environment?

Thanks again.

\end{verbatim}


Brett Henderson brett at bretth.com 
Fri Nov 9 04:55:00 GMT 2012


\begin{verbatim}

Hi Adrià,

Simply calling main should be okay, but you'll need to configure the
classpath beforehand.  That's what the classworlds launcher does for you.
During startup, Osmosis scans the classpath for all instances of
osmosis-plugins.conf and uses them to dynamically register plugins.  If it
doesn't find the pbf plugin (ie. the pbf jar file isn't on the application
classpath) then you'll see the missing task error.

Brett

\end{verbatim}


Adrià Ribatallada Torelló achtungwolf at gmail.com 
Fri Nov 23 12:09:28 GMT 2012


\begin{verbatim}
Hi folks!

I forgot to thank you all for your help!

At the end I got it working in the phone.

The last problem i commented was my mistake (a shamefully idiotic one)
when passing the parameters to the run method I wasn't separating the
strings correctly and the commandline parser complained to that (as
natural).

So in resume, if the JPF (as Brett suggested) is "deactivated" the
osmosis tool is able to run on an android device (at least some of the
tasks/plugins).

Provided that some minor modifications are done to the lib jar's to
avoid repeated files in the final apk. That's basically removing the
repeated osmosis-plugin.conf file present in the plugins jars, and
then, of course, force the loading of that plugins via the run args
(using -plugin option).

That's probably not a very good solution, because it demands to modify
the source of osmosis, and at the end the idea of running osmosis in
the phone is not very useful to anyone, since processing the data in
the phone is really slow and has plenty of limitations (due to android
limitations I presume), and most of the time prforming the task on a
server or on a local computer  is the smartest way to do it.

But just to let you know, it works.

Thanks!

Sincerely,

Adrià Ribatallada i Torelló.

\end{verbatim}


Brett Henderson brett at bretth.com 
Fri Nov 23 12:24:08 GMT 2012


\begin{verbatim}

Hi Adrià,

On 23 November 2012 23:09, Adrià Ribatallada Torelló
<achtungwolf at gmail.com>wrote:
<snip>

>
> But just to let you know, it works.
>

Thanks for giving us the update.  No doubt the question will come up again
so it's good to hear that it's possible.

Cheers,
Brett

\end{verbatim}

